<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width" />
    <title>菜鸟教程</title>
  </head>
  <body>
    <script src="https://cdn.bootcdn.net/ajax/libs/decimal.js/10.2.0/decimal.min.js"></script>
    <script type="text/javascript">
      console.log("基本数据类型：Number");
      var a = 100;
      console.log(typeof a);

      var b = 12.3;
      console.log(typeof b);

      console.log("abc" / 18);
      console.log("abc" * "abcd");

      console.log("1+2+3=");
      console.log(1 + 2 + 3);

      console.log(
        "如果加号两边都是 Number 类型，此时是数字相加。否则，就是连字符（用来连接字符串）:"
      );
      var a1 = "1";
      var b1 = 2;
      console.log(a1 + b1);

      console.log("-、*、/、%这几个符号会自动进行隐式转换");
      var c = "4" + 3 - 6;
      console.log(c);

      console.log(
        "在 JS 中，整数的运算基本可以保证精确；但是小数的运算，可能会得到一个不精确的结果。所以，千万不要使用 JS 进行对精确度要求比较高的运算。"
      );
      var a3 = 0.1 + 0.2;
      console.log(a3);

      console.log("通过 cdn 的方式引入 decimal.js");
      console.log("加法：");
      var a8 = 0.1;
      var b8 = 0.2;
      console.log(a8 + b8);
      console.log(new Decimal(a8).add(new Decimal(b8)).toNumber());

      console.log("减法：");
      var a9 = 1.0;
      var b9 = 0.7;
      console.log(a9 - b9);
      console.log(new Decimal(a9).sub(new Decimal(b9)).toNumber());

      console.log("乘法：");
      var a7 = 1.01;
      var b7 = 1.003;
      console.log(a7 * b7);
      console.log(new Decimal(a7).mul(new Decimal(b7)).toNumber());

      console.log("除法：");
      var a6 = 0.029;
      var b6 = 10;
      console.log(a6 / b6);
      console.log(new Decimal(a6).div(new Decimal(b6)).toNumber());
    </script>
  </body>
</html>
